/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.openbrew.openbrewrf;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author dchapman
 */
@Entity
@Table(name = "posSale")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "POSSale.findOpenItems", query = "SELECT s FROM POSSale s WHERE s.saleComplete = 'false' ORDER BY s.tabName ASC"),
    @NamedQuery(name = "POSSale.findUnreconciledItems", query = "SELECT s FROM POSSale s WHERE s.reconciled = 'false'"),
    @NamedQuery(name = "POSSale.findClosedItems", query = "SELECT s FROM POSSale s WHERE s.saleComplete = 'true'")})
public class POSSale implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "posSaleID")
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 250)
    @Column(name = "posTabName")
    private String tabName;
    @Basic(optional = false)
    @NotNull
    @Column(name = "posTabOpen")
    @Temporal(TemporalType.TIMESTAMP)
    private Date tabOpenTime;
    @Basic(optional = false)
    @NotNull
    @Column(name = "posTabPaid")
    @Temporal(TemporalType.TIMESTAMP)
    private Date tabPaidTime;
    @Basic(optional = false)
    @NotNull
    @Column(name = "posTabState")
    private int tabState;
    @Basic(optional = false)
    @NotNull
    @Column(name = "posSaleComplete")
    private boolean saleComplete;
    @Basic(optional = false)
    @NotNull
    @Column(name = "posSaleReconciled")
    private boolean reconciled;
    @Basic(optional = false)
    @NotNull
    @Column(name = "saleCash")
    private float saleCash;
    @Basic(optional = false)
    @NotNull
    @Column(name = "saleCredit")
    private float saleCredit;
    @Basic(optional = false)
    @NotNull
    @Column(name = "saleGiftCard")
    private float saleGiftCard;
    @Basic(optional = false)
    @NotNull
    @Column(name = "saleOther")
    private float saleOther;
    @Basic(optional = false)
    @NotNull
    @Column(name = "loyaltyMoney")
    private float loyaltyMoney;
    @JoinColumn(name = "loyaltyNumber", referencedColumnName = "loyaltyID", nullable=true)
    @ManyToOne(optional = true)
    private PosLoyaltyCard loyaltyCard;
    @OneToMany(cascade=CascadeType.REFRESH, fetch=FetchType.EAGER)
    @JoinTable(
        name="posJTSaleToItem",
        joinColumns={ @JoinColumn(name="posSaleID", referencedColumnName="posSaleID")},
        inverseJoinColumns={ @JoinColumn(name="lineItemID", referencedColumnName="lineItemID", unique=true)}
    )
    private List<POSLineItems> lineItemTypeCollection;

    public POSSale() {
    }

    public POSSale(Integer id) {
        this.id = id;
    }

    public POSSale(Integer id, String tabName, Date tabOpenTime, Date tabPaidTime, int tabState, boolean saleComplete, boolean reconciled, float saleCash, float saleCredit, float saleGiftCard, float saleOther) {
        this.id = id;
        this.tabName = tabName;
        this.tabOpenTime = tabOpenTime;
        this.tabPaidTime = tabPaidTime;
        this.tabState = tabState;
        this.saleComplete = saleComplete;
        this.reconciled = reconciled;
        this.saleCash = saleCash;
        this.saleCredit = saleCredit;
        this.saleGiftCard = saleGiftCard;
        this.saleOther = saleOther;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTabName() {
        return tabName;
    }

    public void setTabName(String tabName) {
        this.tabName = tabName;
    }

    public Date getTabOpenTime() {
        return tabOpenTime;
    }

    public void setTabOpenTime(Date tabOpenTime) {
        this.tabOpenTime = tabOpenTime;
    }

    public Date getTabPaidTime() {
        return tabPaidTime;
    }

    public void setTabPaidTime(Date tabPaidTime) {
        this.tabPaidTime = tabPaidTime;
    }

    public int getTabState() {
        return tabState;
    }

    public void setTabState(int tabState) {
        this.tabState = tabState;
    }

    public boolean isSaleComplete() {
        return saleComplete;
    }

    public void setSaleComplete(boolean saleComplete) {
        this.saleComplete = saleComplete;
    }

    public boolean isReconciled() {
        return reconciled;
    }

    public void setReconciled(boolean reconciled) {
        this.reconciled = reconciled;
    }

    public List<POSLineItems> getLineItemTypeCollection() {
        return lineItemTypeCollection;
    }

    public void setLineItemTypeCollection(List<POSLineItems> lineItemTypeCollection) {
        this.lineItemTypeCollection = lineItemTypeCollection;
    }

    public float getSaleCash() {
        return saleCash;
    }

    public void setSaleCash(float saleCash) {
        this.saleCash = saleCash;
    }

    public float getSaleCredit() {
        return saleCredit;
    }

    public void setSaleCredit(float saleCredit) {
        this.saleCredit = saleCredit;
    }

    public float getSaleGiftCard() {
        return saleGiftCard;
    }

    public void setSaleGiftCard(float saleGiftCard) {
        this.saleGiftCard = saleGiftCard;
    }

    public float getSaleOther() {
        return saleOther;
    }

    public void setSaleOther(float saleOther) {
        this.saleOther = saleOther;
    }

    public float getLoyaltyMoney() {
        return loyaltyMoney;
    }

    public void setLoyaltyMoney(float loyaltyMoney) {
        this.loyaltyMoney = loyaltyMoney;
    }

    public PosLoyaltyCard getLoyaltyCard() {
        return loyaltyCard;
    }

    public void setLoyaltyCard(PosLoyaltyCard loyaltyCard) {
        if(loyaltyCard != null && loyaltyCard.getLoyaltyID() != null){
            this.loyaltyCard = loyaltyCard;
        }
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof POSSale)) {
            return false;
        }
        POSSale other = (POSSale) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.openbrew.openbrewrf.possale[ id=" + id + " ]";
    }
    
}
